﻿namespace SendKeys.Controls
{
	using System.Collections.Generic;
	using System.Configuration;
	using System.Linq;
	using System.Windows.Forms;
	using SendKeys.Config;

	public partial class ShortCutControl : UserControl, IUserControl
	{
		public ShortCutControl()
		{
			InitializeComponent();
		}

		public void DataBind()
		{
			this.cbProcess.DataSource = ShortCutControl.RegisteredApps.ToList();
			this.cbProcess.ValueMember = "ProcessName";
			this.cbProcess.DisplayMember = "DisplayName";
		}

		private static List<RegisteredAppElement> _registeredApps;
		private static IEnumerable<RegisteredAppElement> RegisteredApps
		{
			get
			{
				if (_registeredApps == null)
				{
					RegisteredAppsConfigurationSection apps = (RegisteredAppsConfigurationSection)ConfigurationManager.GetSection("RegisteredApps");
					_registeredApps = new List<RegisteredAppElement>();
					foreach (RegisteredAppElement item in apps.RegisteredApps)
					{
						_registeredApps.Add(new RegisteredAppElement() { ProcessName = item.ProcessName, DisplayName = item.DisplayName });
					}
				}
				return _registeredApps;
			}
		}
	}
}
